var app = getApp()
var mydata = require('../../utils/data')
var util = require('../../utils/util')
var req = require('../../utils/reqUtils.js')

Page( {
  data: {
    addrArray:util.replacePhone(mydata.userData().addrs,true),
    addrIndex:0,
    date : new Date().getFullYear()+"-"+(new Date().getMonth()+1)+"-"+new Date().getDate(),
    time : '12:00',
    bookToastHidden:true,
    message:'',
    bookId:'',
    list: {}
  },
  onLoad: function (options) {
  console.log(options.unit)
  var obj = JSON.parse(options.unit);
   this.setData({
      list:obj
   })
  },
  closeHide:function(e){
    this.setData({
      ismask: 'none'
    });
  },
  // 地址选择
  bindAddrPickerChange : function(e){
    console.log('Addrpicker发送选择改变，携带值为', e.detail.value)
    this.setData({
      addrIndex: e.detail.value
    })
  },
  getMyInfo:function(e){
    var that = this
    wx.login({
      success: function (res) {
        console.log('code:'+res.code)
        }
    })
    let info = e.detail.userInfo
    this.setData({
      src:info.avatarUrl,
      nickName:info.nickName,
      isLogin:true
    })
  },
  bindToastTap:function(e){
    console.log(wx.getStorageSync('nickName'))
    var that=this;
    console.log({
      serviceId:that.data.list.id,
      date:that.data.date+" "+that.data.time,
      message:that.data.message,
      nickName:wx.getStorageSync('nickName'),
      price: that.data.list.price
    });
    that.setData({
      bookToastHidden:false
    })
    req.post('/BookServiceAction', {
      serviceId:that.data.list.id,
      date:that.data.date+" "+that.data.time,
      message:that.data.message,
      nickName:wx.getStorageSync('nickName'),
      price: that.data.list.price
    }, 1)
    .then(res => {
      console.log(res.data[0].id)
        that.setData({
          bookToastHidden:false,
          bookId:res.data[0].id
      })
    })
  },
  hideToast:function(){
    this.setData({
          bookToastHidden:true
      })
  },
  // 日期选择
  bindDateChange: function(e){
    console.log('date picker发送选择改变，携带值为', e.detail.value)
    this.setData({
          date: e.detail.value
    })
  },
  // 时间选择
  bindTimeChange: function(e){
    console.log('time picker发送选择改变，携带值为', e.detail.value)
    this.setData({
          time: e.detail.value
    })
  }
})